package kernel;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;

public class Core {

	private ArrayList<double[][][]> timeFluidMatrix;
	
	public Core()
	{
		timeFluidMatrix = new ArrayList<double[][][]>();
	}
	
	public void readFile(File file) throws Exception
	{
		BufferedReader in = new BufferedReader(new FileReader(file));
		
		int width = Integer.parseInt(in.readLine());
		int height = Integer.parseInt(in.readLine());
		int depth = Integer.parseInt(in.readLine());
		
		double[][][] fluidMatrix_i = new double[width][height][depth];
		String line = "";
		int counterHeight = 0;
		int counterDepth = 0;
		while((line = in.readLine())!= null)
		{
			String[] parsedLine = line.split("\\s+");
			for(int i = 0; i <parsedLine.length; i++)
			{
				fluidMatrix_i[i][counterHeight][counterDepth] = Double.parseDouble(parsedLine[i]);
			}
			counterHeight++;
			if(counterHeight >= height)
			{
				counterHeight = 0;
				counterDepth++;
			}
			if(counterDepth >= depth)
			{
				timeFluidMatrix.add(fluidMatrix_i);
//				System.out.println(timeFluidMatrix.size());
				counterHeight = 0;
				counterDepth = 0;
				fluidMatrix_i = new double[width][height][depth];
			}
		}
		in.close();
//		System.out.println("wow, increible, funciono!!!");
	}
	
	public double[][][] getMatrix(int index)
	{
		return timeFluidMatrix.get(index);
	}
	
	public int getFrames()
	{
		return timeFluidMatrix.size();
	}
}
